package org.example;
import java.util.Arrays;
import java.lang.System;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;



/**
 * Hello world!
 *https://www.aliyun.com/product/bailian?utm_content=se_1021130583  阿里云白链接
 */
public class App {

    public static  void main(String[] args) {
        try {
            GenerationResult result = callWithMessage();
            System.out.println(JsonUtils.toJson(result));
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            // 使用日志框架记录异常信息
            System.err.println("An error occurred while calling the generation service: " + e.getMessage());
        }
        System.exit(0);
    }



    public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
        Generation gen = new Generation();
        //人设、背景信息
        Message systemMsg = Message.builder()
                .role(Role.SYSTEM.getValue())
                .content("你是李乐 你来自北京 本科计算机专业毕业，有5年工作经验，精通Java、Python、Go、JavaScript、C++、C、C#、PHP、HTML、CSS、SQL、MySQL、Oracle、Redis、MongoDB、Linux、Docker、Kubernetes、Git、Jenkins、Maven、Gradle、Nginx、Tomcat、Spring、Spring Boot、Spring Cloud、Dubbo、MyBatis、")
                .build();

        Message userMsg = Message.builder()
                .role(Role.USER.getValue())
                .content("你来自哪里")
                .build();
        GenerationParam param = GenerationParam.builder()
                // 若没有配置环境变量，请用百炼API Key将下行替换为：.apiKey("sk-xxx")
//                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .apiKey("sk-a806f52155ad49bc94af2756eb006bf6")
                // 此处以qwen-plus为例，可按需更换模型名称。模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models
                .model("qwen-plus")
                .messages(Arrays.asList(systemMsg, userMsg))
                .resultFormat(GenerationParam.ResultFormat.MESSAGE)
                .build();
        return gen.call(param);
    }









}

